{% extends "auth/base.html" %}

{% block title %}用户仪表板 - Flask权限管理系统{% endblock %}

{% block content %}
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <h1 class="h3 mb-4">用户仪表板</h1>
        </div>
    </div>
    
    <div class="row">
        <div class="col-md-4 mb-4">
            <div class="card">
                <div class="card-header bg-primary text-white">
                    <h5 class="mb-0"><i class="fas fa-user"></i> 个人信息</h5>
                </div>
                <div class="card-body">
                    <ul class="list-group list-group-flush">
                        <li class="list-group-item d-flex justify-content-between align-items-center">
                            用户名
                            <span class="badge bg-primary rounded-pill">{{ current_user.username }}</span>
                        </li>
                        <li class="list-group-item d-flex justify-content-between align-items-center">
                            邮箱
                            <span class="badge bg-info rounded-pill">{{ current_user.email }}</span>
                        </li>
                        <li class="list-group-item d-flex justify-content-between align-items-center">
                            注册时间
                            <span class="badge bg-secondary rounded-pill">{{ current_user.created_at.strftime('%Y-%m-%d') if current_user.created_at else '未知' }}</span>
                        </li>
                        <li class="list-group-item d-flex justify-content-between align-items-center">
                            最后登录
                            <span class="badge bg-success rounded-pill">{{ current_user.last_login.strftime('%Y-%m-%d %H:%M') if current_user.last_login else '从未登录' }}</span>
                        </li>
                        <li class="list-group-item d-flex justify-content-between align-items-center">
                            登录次数
                            <span class="badge bg-warning rounded-pill">{{ user_stats.login_count }}</span>
                        </li>
                    </ul>
                </div>
                <div class="card-footer">
                    <a href="{{ url_for('auth.profile') }}" class="btn btn-primary btn-sm">查看详细资料</a>
                    <a href="{{ url_for('auth.change_password') }}" class="btn btn-outline-secondary btn-sm">修改密码</a>
                </div>
            </div>
        </div>
        
        <div class="col-md-4 mb-4">
            <div class="card">
                <div class="card-header bg-success text-white">
                    <h5 class="mb-0"><i class="fas fa-user-tag"></i> 用户角色</h5>
                </div>
                <div class="card-body">
                    {% if user_stats.roles %}
                    <ul class="list-group list-group-flush">
                        {% for role in user_stats.roles %}
                        <li class="list-group-item">
                            <div class="d-flex justify-content-between align-items-center">
                                <span>{{ role.name }}</span>
                                <span class="badge bg-success rounded-pill">{{ role.description or '无描述' }}</span>
                            </div>
                        </li>
                        {% endfor %}
                    </ul>
                    {% else %}
                    <p class="text-muted">您尚未分配任何角色</p>
                    {% endif %}
                </div>
            </div>
        </div>
        
        <div class="col-md-4 mb-4">
            <div class="card">
                <div class="card-header bg-warning text-dark">
                    <h5 class="mb-0"><i class="fas fa-key"></i> 用户权限</h5>
                </div>
                <div class="card-body">
                    {% if user_stats.permissions %}
                    <ul class="list-group list-group-flush">
                        {% for permission in user_stats.permissions %}
                        <li class="list-group-item">
                            <div class="d-flex justify-content-between align-items-center">
                                <span>{{ permission.name }}</span>
                                <span class="badge bg-warning text-dark rounded-pill">{{ permission.description or '无描述' }}</span>
                            </div>
                        </li>
                        {% endfor %}
                    </ul>
                    {% else %}
                    <p class="text-muted">您没有任何特殊权限</p>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
    
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header bg-info text-white">
                    <h5 class="mb-0"><i class="fas fa-tachometer-alt"></i> 快速操作</h5>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-3 mb-3">
                            <div class="d-grid">
                                <a href="{{ url_for('auth.profile') }}" class="btn btn-outline-primary">
                                    <i class="fas fa-user-circle"></i> 个人资料
                                </a>
                            </div>
                        </div>
                        <div class="col-md-3 mb-3">
                            <div class="d-grid">
                                <a href="{{ url_for('auth.change_password') }}" class="btn btn-outline-secondary">
                                    <i class="fas fa-lock"></i> 修改密码
                                </a>
                            </div>
                        </div>
                        {% if current_user.is_administrator() %}
                        <div class="col-md-3 mb-3">
                            <div class="d-grid">
                                <a href="{{ url_for('admin.dashboard') }}" class="btn btn-outline-danger">
                                    <i class="fas fa-cogs"></i> 管理面板
                                </a>
                            </div>
                        </div>
                        {% endif %}
                        <div class="col-md-3 mb-3">
                            <div class="d-grid">
                                <a href="{{ url_for('auth.logout') }}" class="btn btn-outline-danger">
                                    <i class="fas fa-sign-out-alt"></i> 退出登录
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}